package org.activequant.core.domainmodel.marketscanner;

import static org.activequant.util.tools.IdentityUtils.equalsTo;
import static org.activequant.util.tools.IdentityUtils.safeCompare;
import static org.activequant.util.tools.IdentityUtils.safeHashCode;

import java.io.Serializable;
/**
 * MarketScanRow implements Comparable&lt;MarketScanRow&gt;, Serializable<br/>
 * Holds the following associated variables:
 * <ul>
 * <li>id(Long)</li>
 * <li>ranking(Integer)</li>
 * <li>instrumentSpecificationDetails(InstrumentSpecificationDetails)</li>
 * <li>distance(String)</li>
 * <li>benchmark(String)</li>
 * <li>projection(String)</li>
 * <li>legsStr(String)</li>
 * </ul>
 * @author Dimitar
 *
 */
public class MarketScanRow implements Comparable<MarketScanRow>, Serializable {
	private static final long serialVersionUID = 1205378460744442471L;
	/**
	 * private Long id = null;
	 */
	private Long id = null;
	/**
	 * private Integer ranking;
	 */
//	private Integer ranking;//temporary
	/**
	 * private InstrumentSpecificationDetails instrumentSpecificationDetails;
	 */
	private InstrumentSpecificationDetails instrumentSpecificationDetails;
	/**
	 * private String distance;
	 */
	private String distance;
	/**
	 * private String benchmark;
	 */
	private String benchmark;
	/**
	 * private String projection;
	 */
	private String projection;
	/**
	 * private String legsStr;
	 */
	private String legsStr;
	/**
	 * An empty MarketScanRow(implements Comparable&lt;MarketScanRow&gt;, Serializable) constructor
	 */
	public MarketScanRow(){
		
	}
	/**
	 * Constructs a MarketScanRow(implements Comparable&lt;MarketScanRow&gt;, Serializable) using the given specDetails(InstrumentSpecificationDetails), distance(String), benchmark(String), projection(String) and legsStr(String)
	 * to set its associated variables.
	 * @param specDetails
	 * @param distance
	 * @param benchmark
	 * @param projection
	 * @param legsStr
	 */
	public MarketScanRow(/*int ranking, */InstrumentSpecificationDetails specDetails, String distance, String benchmark, String projection, String legsStr) {
//		this.ranking = ranking;
		this.instrumentSpecificationDetails = specDetails;
		this.distance = distance;
		this.benchmark = benchmark;
		this.projection = projection;
		this.legsStr = legsStr;
	}
	/**
	 * returns the associated id(Long)
	 * @return
	 */
	public Long getId() {
		return id;
	}
	/**
	 * returns the associated ranking(Integer)
	 * @return
	 */
//	public Integer getRanking() {
//		return ranking;
//	}
	/**
	 * returns the associated instrumentSpecificationDetails(InstrumentSpecificationDetails)
	 * @return
	 */
	public InstrumentSpecificationDetails getInstrumentSpecificationDetails() {
		return instrumentSpecificationDetails;
	}
	/**
	 * returns the associated distance(String)
	 * @return
	 */
	public String getDistance() {
		return distance;
	}
	/**
	 * returns the associated benchmark(String)
	 * @return
	 */
	public String getBenchmark() {
		return benchmark;
	}
	/**
	 * returns the associated projection(String)
	 * @return
	 */
	public String getProjection() {
		return projection;
	}
	/**
	 * returns the associated legsStr(String)
	 * @return
	 */
	public String getLegsStr() {
		return legsStr;
	}
	/**
	 * sets the associated id(Long) with the given id(Long)
	 * @param id
	 */
	public void setId(Long id) {
		this.id = id;
	}
	/**
	 * sets the associated ranking(Integer) with the given ranking(Integer)
	 * @param ranking
	 */
//	public void setRanking(Integer ranking) {
//		this.ranking = ranking;
//	}
	/**
	 * sets the associated instrumentSpecificationDetails(InstrumentSpecificationDetails) with the given instrumentSpecificationDetails(InstrumentSpecificationDetails)
	 * @param instrumentSpecificationDetails
	 */
	public void setInstrumentSpecificationDetails(InstrumentSpecificationDetails instrumentSpecificationDetails) {
		this.instrumentSpecificationDetails = instrumentSpecificationDetails;
	}
	/**
	 * sets the associated distance(String) with the given distance(String)
	 * @param distance
	 */
	public void setDistance(String distance) {
		this.distance = distance;
	}
	/**
	 * sets the associated benchmark(String) with the given benchmark(String)
	 * @param benchmark
	 */
	public void setBenchmark(String benchmark) {
		this.benchmark = benchmark;
	}
	/**
	 * sets the associated projection(String) with the given projection(String)
	 * @param projection
	 */
	public void setProjection(String projection) {
		this.projection = projection;
	}
	/**
	 * sets the associated legsStr(String) with the given legsStr(String)
	 * @param legsStr
	 */
	public void setLegsStr(String legsStr) {
		this.legsStr = legsStr;
	}
	/**
	 * {@inheritDoc}
	 */
	@Override
	public int hashCode() {
		// ATTENTION: keep in sync with compareTo();
		return 
//		safeHashCode(this.getRanking()) + 
		safeHashCode(this.getInstrumentSpecificationDetails())+ 
		safeHashCode(this.getDistance())+ 
		safeHashCode(this.getBenchmark())+ 
		safeHashCode(this.getProjection())+ 
		safeHashCode(this.getLegsStr());
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public boolean equals(Object other) {
		// NOTE: delegates to compareTo()
		return equalsTo(this, other);
	}
	
	/**
	 * {@inheritDoc}
	 */
	public int compareTo(MarketScanRow other) {
		// ATTENTION: keep in sync with hashCode();
		int rc;
//		rc = safeCompare(this.getRanking(), other.getRanking());
//		if (rc != 0) return rc;
		rc = safeCompare(this.getInstrumentSpecificationDetails(), other.getInstrumentSpecificationDetails());
		if (rc != 0) return rc;
		rc = safeCompare(this.getDistance(), other.getDistance());
		if (rc != 0) return rc;
		rc = safeCompare(this.getBenchmark(), other.getBenchmark());
		if (rc != 0) return rc;
		rc = safeCompare(this.getProjection(), other.getProjection());
		if (rc != 0) return rc;
		rc = safeCompare(this.getLegsStr(), other.getLegsStr());
		if (rc != 0) return rc;
		return rc;
	}
	
    @Override
    public String toString() {
//		String ret= ranking==null?"":(ranking+"\t");
		String ret= instrumentSpecificationDetails==null?"":(instrumentSpecificationDetails+"\t");
		ret += distance==null?"":(distance+ "\t"); 
		ret += benchmark==null?"":(benchmark+ "\t"); 
		ret += projection==null?"":(projection+ "\t");
		ret += legsStr==null?"":(legsStr+ "\t");
		return ret;
	}
	
}
